#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > r12_stg.info <<'%EOF%'
   r12_stg
   --------------
   Molecule:         Methane (CH4)
   Wave Function:    MP2-R12 / 6-311G
   Test Purpose:     Check MP2-R12/B method with auxiliary basis and
                     a Slater-type geminal (STG) with exponent 0.5.
                     The hybrid and CABS approaches are used. 

                     The orbital-invariant energies must be equal
                     to those of test case r12_loc.
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > r12_stg.mol <<'%EOF%'
BASIS
6-311G Turbomole-TZVPP
Direct MP2-R12/B calculation using symmetry                                     
                                                                                
    4  0 2 XY XZ      0.10D-14
 1      6.    1
C        0.0000000000000     0.0000000000000     0.0000000000000
 1      1.    1
H        1.2767310000000     1.2767310000000     1.2767310000000
 2      6.    1
C        0.0000000000000     0.0000000000000     0.0000000000000
 2      1.    1 
H        1.2767310000000     1.2767310000000     1.2767310000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > r12_stg.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTION
.DIRECT
*MOLBAS
.R12AUX
**INTEGRALS
.R12STG
0.5
3
**WAVE FUNCTIONS
.HF
.CC
*SCF INPUT
.THRESH
 1D-10
*ORBITAL INPUT
.MOSTART
 H1DIAG
*CC INPUT
#.HERDIR
.FROIMP
 1 0 0 0
 0 0 0 0
.MP2
.PRINT
 3 
*R12 INPUT
.CABS
.R12XXL
**END OF DALTON INPUT
%EOF%

#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >r12_stg.check
cat >>r12_stg.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

#
# ! Original MP2-R12 method !
#              MP2-R12/A   correlation energy =   -0.370487621
#              MP2-R12/A'  correlation energy =   -0.369767358
#              MP2-R12/B   correlation energy =   -0.271114602
# ! Ansatz 1 !
#              MP2-R12/A   correlation energy =   -0.195245122
#              MP2-R12/A'  correlation energy =   -0.194463532
#              MP2-R12/B   correlation energy =   -0.173373550
# ! Ansatz 2 !
#              MP2-R12/A   correlation energy =   -0.255315041
#              MP2-R12/A'  correlation energy =   -0.254283967
#              MP2-R12/B   correlation energy =   -0.209981733
#
CRIT1=`$GREP "MP2-R12/B   correlation energy =   (-0| -)\.17337355" $log | wc -l`
TEST[1]=`expr	$CRIT1`
CTRL[1]=1
ERROR[1]="MP2-R12/B ENERGY NOT CORRECT"

CRIT2=`$GREP "MP2-R12/B   correlation energy =   (-0| -)\.20998173" $log | wc -l`
TEST[2]=`expr	$CRIT2`
CTRL[2]=2
ERROR[2]="MP2-R12/B ENERGY NOT CORRECT"

PASSED=1
for i in 2 
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
